// 对称差 -- 去重
// xor([1, 2, 3, 4, 5, 6, 6, 7, 7], [3, 4, 5, 11, 12]) => [ 1, 2, 6, 7, 11, 12 ]
import { union } from "./union"
import { difference, differenceBy, differenceWith } from "./difference"

export function xor(X: any[], Y: any[]): any[] {
  if (X == null || Y == null) return []
  return union(difference(X, Y), difference(Y, X))
}

export function xorBy(X: any[], Y: any[], mapFn: (element: any) => any): any[] {
  if (X == null || Y == null) return []
  return union(differenceBy(X, Y, mapFn), differenceBy(Y, X, mapFn))
}

export function xorWith(X: any[], Y: any[], isEqual: (x: any, y: any) => boolean): any[] {
  if (X == null || Y == null) return []
  return union(differenceWith(X, Y, isEqual), differenceWith(Y, X, isEqual))
}
